package com.xls.dormitoryservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xls.dormitoryservice.service.EmployeeService;
import com.xls.base.model.Employee;
import com.xls.base.mapper.EmployeeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xls.dormitoryservice.vo.EmployeeQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xls
 * @since 2021-03-23
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    public Page<Employee> getEmployeePage(Integer page, Integer limit, EmployeeQuery employeeQuery) {
        QueryWrapper<Employee> employeeQueryWrapper = new QueryWrapper<>();
        String employeeNumber = employeeQuery.getEmployeeNumber();
        String name = employeeQuery.getName();
        String gender = employeeQuery.getGender();
        String building = employeeQuery.getBuilding();
        String phone = employeeQuery.getPhone();
        employeeQueryWrapper.likeRight(!StringUtils.isEmpty(employeeNumber), "employee_number", employeeNumber)
                .likeRight(!StringUtils.isEmpty(name), "name", name)
                .eq(!StringUtils.isEmpty(gender), "gender", gender)
                .eq(!StringUtils.isEmpty(building), "building", building)
                .likeRight(!StringUtils.isEmpty(phone), "phone", phone)
                .eq("is_deleted", 0);
        return employeeMapper.getEmployeePage(new Page<>(page, limit), employeeQueryWrapper);
    }

}
